package com.neusoft.SPNursingHome.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.neusoft.SPNursingHome.po.MealCalendar;
import com.neusoft.SPNursingHome.po.ResponseBean;
import com.neusoft.SPNursingHome.service.MealCalendarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.neusoft.SPNursingHome.po.MealCalendarWithFood;

import java.util.List;


@RestController
@RequestMapping("/mealCalendar")
public class MealCalendarController {

    @Autowired
    private MealCalendarService service;

    @GetMapping("/list")
    public ResponseBean<List<MealCalendar>> listAll() {
        return service.listAll();
    }

    @GetMapping("/listWithFoodName")
    public ResponseBean<IPage<MealCalendarWithFood>> listWithFoodName(
            @RequestParam(required = false) String mealCalendarDate,
            @RequestParam(required = false) String mealCalendarTime,
            @RequestParam(required = false) String foodName,
            @RequestParam(required = false) String foodType,
            @RequestParam(defaultValue = "1") long page,
            @RequestParam(defaultValue = "10") long size) {

        return service.listWithFoodName(
                mealCalendarDate, mealCalendarTime, foodName, foodType, page, size);
    }


    @GetMapping("/{id}")
    public ResponseBean<MealCalendar> getById(@PathVariable Integer id) {
        return service.getById(id);
    }

    @PostMapping("/create")
    public ResponseBean<Void> create(@RequestBody MealCalendar mc) {
        return service.create(mc);
    }

    @PutMapping("/update")
    public ResponseBean<Void> update(@RequestBody MealCalendar mc) {
        return service.update(mc);
    }

    @DeleteMapping("/delete/{id}")
    public ResponseBean<Void> delete(@PathVariable Integer id) {
        return service.deleteById(id);
    }
}
